package middleware

import (
	"moft/model"
	"net/http"

	"github.com/gin-gonic/gin"
)

func Admin() gin.HandlerFunc {
	return func(c *gin.Context) {
		sess := model.NewSession(c.Request)

		isAdmin := sess.GetBool("is_admin")
		if !isAdmin {
			c.AbortWithStatus(http.StatusForbidden)
			return
		}

		c.Next()
	}
}
